package pw.hais.etgsh.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListView;

import com.squareup.okhttp.Response;

import java.util.ArrayList;
import java.util.List;

import pw.hais.etgsh.R;
import pw.hais.etgsh.activity.ArticleListActivity;
import pw.hais.etgsh.activity.DianTaiPlayerActivity;
import pw.hais.etgsh.adapter.DianTaiListAdapter;
import pw.hais.etgsh.adapter.GuShiTypeAdapter;
import pw.hais.etgsh.app.BaseFragment;
import pw.hais.etgsh.dao.DianTaiDao;
import pw.hais.etgsh.model.DianTaiTypeModel;
import pw.hais.etgsh.model.GuShiTypeModel;
import pw.hais.http.base.OnHttpListener;

/**
 * 电台
 * Created by hais1992 on 2016/1/23/023.
 */
public class DianTaiFragment extends BaseFragment implements AdapterView.OnItemClickListener {
    private ListView listview;
    private DianTaiListAdapter dianTaiListAdapter;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_diantai, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        listview = (ListView) view.findViewById(R.id.listview);
        listview.setOnItemClickListener(this);

        loadDataToView();
    }

    private void loadDataToView() {
        loadDialogShow("加载列表中...");
        DianTaiDao.getAllType(new OnHttpListener<List<DianTaiTypeModel>>() {
            @Override
            public void onSuccess(Response response, List<DianTaiTypeModel> data) {
                loadDialogDismiss();
                dianTaiListAdapter = new DianTaiListAdapter(data);
                listview.setAdapter(dianTaiListAdapter);
            }
        });
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(context,DianTaiPlayerActivity.class);
        intent.putExtra(DianTaiPlayerActivity.INTENT_ENTITY_KEY,dianTaiListAdapter.getItem(position));
        startActivity(intent);
    }
}
